package DataModel.DesignRulesManager;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;

import DataModel.CommonLibrary.CommonDefs.Layer;
import DataModel.DesignRulesManager.CCommonUtils.EDesignRuleType;

public class CDesignRulesManager 
{
	/***************************************************/
	/****** C'tor **************************************/
	/***************************************************/
	public  CDesignRulesManager()
	{}
	
	/***************************************************/
	/****** Members ************************************/
	/***************************************************/
	private LinkedList<CDesignRule> m_drList;
	private Integer m_drcConst;
	
	/***************************************************/
	/****** Public functions ***************************/
	/***************************************************/
	public void RunFile(String filePath)
	{
		File file = new File(filePath);		
		URL fileURL = null;
		
		try 
		{
			fileURL = file.getAbsoluteFile().toURI().toURL();
		}
		catch (MalformedURLException e) 
		{
			e.printStackTrace();
		}
		
		m_drList = new LinkedList<CDesignRule>();
		
		CDesignRulesParser drParser = new CDesignRulesParser(fileURL,m_drList, m_drcConst);
		
		drParser.Parse();
	}
	
	
	/**
	 * Get the value of a design rule
	 * @param layer1
	 * @param layer2
	 * @param designRuleType
	 * @return -1 on failure
	 */
	public double GetRuleValue(Layer layer1, Layer layer2, EDesignRuleType designRuleType)
	{
		for (CDesignRule drc : m_drList) 
		{
			if(
					drc.getFirstLayer() == layer1
					&& drc.getSecondLayer() == layer2
					&& drc.getType() == designRuleType
				)
				return drc.getValue();
		}
		
		return -1; 
	}
	
	public double GetRuleValue(Layer layer, EDesignRuleType designRuleType)
	{
		for (CDesignRule drc : m_drList) 
		{
			if(
					drc.getFirstLayer() == layer
					&& drc.getType() == designRuleType
				)
				return drc.getValue();
		}
		
		return -1;
	}
}












